package
{
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	/**
	 *主程序的壳 
	 * @author YY
	 * 
	 */
	public class InitMain extends Sprite
	{
		[Embed(source="../bin-debug/Main.swf", mimeType="application/octet-stream")]
		public var _Main:Class;
		public var callback:Function;//加载完成回调函数
		public function InitMain()
		{
			
		}
		
		/**
		 * 启动加载 
		 */		
		public function start():void{
			var loadContext:LoaderContext = new LoaderContext();
			loadContext.applicationDomain = ApplicationDomain.currentDomain;
			var loader:Loader=new Loader();
			loader.loadBytes(new _Main(),loadContext);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
		}
		
		/**
		 * 加载完成 
		 * @param evt
		 */		
		private function loadComplete(evt:Event):void{
			var info:LoaderInfo = LoaderInfo(evt.target);
			var domain:ApplicationDomain = info.applicationDomain;
			var main:Class = domain.getDefinition("Main") as Class;
			this.callback(main);
			this.callback = null;
		}
	}
}